package com.itcat.controller;/*
 * @Author: gonhsl
 * @Date:2022-04-02-15:58
 * */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itcat.common.CommonPage;
import com.itcat.common.CommonResult;
import com.itcat.mysql.pojo.SmsFlashPromotion;
import com.itcat.service.SmsFlashPromotionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flash")
public class SmsFlashPromotionController {
    @Autowired
    private SmsFlashPromotionService smsFlashPromotionService;
    /**
     * Description:获取活动详情
     * date: 2022/4/2 15:59
     * @author: chp
     * @since JDK 1.8
     */
@GetMapping("/{id}")
    public CommonResult findFlash(@PathVariable String id){
//    smsFlashPromotionService.findFlash(id);
    return CommonResult.success();
}
@GetMapping("/list")
    public CommonResult findList(@RequestParam Integer pageNum,
                                 @RequestParam Integer pageSize,
                                 String keyword){
    Page<SmsFlashPromotion> page = smsFlashPromotionService.findList(pageNum, pageSize, keyword);
    CommonPage<SmsFlashPromotion> restPage = CommonPage.restPage(page);

    return CommonResult.success(restPage);
}
/**
 * Description:添加活动
 * date: 2022/4/2 18:10
 * @author: chp
 * @since JDK 1.8
 */
@PostMapping("/create")
    public CommonResult create(@RequestBody SmsFlashPromotion smsFlashPromotion){
    smsFlashPromotionService.create(smsFlashPromotion);
    return CommonResult.success();

}

    /**
     * Description:删除活动
     * date: 2022/4/2 18:10
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable Integer id) {
        smsFlashPromotionService.delete(id);
        return CommonResult.success();

    }

    /**
     * Description:修改上下线状态
     * date: 2022/4/2 18:10
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/status/{id}")
    public CommonResult updateStatus(@PathVariable Integer id ,@RequestParam Integer status) {
        smsFlashPromotionService.updateStatus(id,status);
        return CommonResult.success();

    }
 /**
     * Description:编辑活动
     * date: 2022/4/2 18:10
     *
     * @author: chp
     * @since JDK 1.8
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@RequestBody SmsFlashPromotion smsFlashPromotion,
                               @PathVariable Integer id) {

        smsFlashPromotionService.update(smsFlashPromotion,id);
        return CommonResult.success();

    }

}
